﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
using System.Web.Script.Serialization;
using DynamicJsonParser;
using System.Collections;
namespace Easycmd
{
    static class Program
    {
        static void a()
        {
            string demoJson = @"
{
    'lastopens':
    {
        'left':['c:\\','c:\\'],
        'right':['c:\\','c:\\windows\\']
       
    }
}
    ";


            var serializer = new JavaScriptSerializer();
            serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
            dynamic easycmd = serializer.Deserialize<object>(demoJson);
            Console.WriteLine(easycmd.lastopens.left);
            Console.WriteLine(easycmd.lastopens.right);
            Console.WriteLine(easycmd.lastopens.right[0]);

            Console.ReadLine();
            // create json
            dynamic easycmdObj = new DynamicJsonObject();
            dynamic lastopensObj = new DynamicJsonObject();
            ArrayList leftObj = new ArrayList();
            ArrayList rightObj = new ArrayList();
            leftObj.Add("c:\\");
            leftObj.Add("c:\\");
            rightObj.Add("c:\\windows");
            lastopensObj.left = leftObj;
            lastopensObj.right = rightObj;
            easycmdObj.lastopens = lastopensObj;
            Console.WriteLine(easycmdObj.ToString());
            MessageBox.Show(easycmdObj.ToString());
            Console.ReadLine();
            return;
        }
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            //a();
            //return;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            HookUnhandledException();
            Application.Run(new FormMain());
        }
        public static void HookUnhandledException()
        {
            Application.ThreadException += new ThreadExceptionEventHandler(DoHandleException);            
        }

        private static void DoHandleException(object sender, ThreadExceptionEventArgs args)
        {
            Exception e = args.Exception;
            if (e is AbortException)
            {
                // ingores 
                if (e.Message != "") MessageBox.Show(e.Message);
            }else
                MessageBox.Show(e.Message);
        }
    }
}